﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model;

namespace DAL
{
    public class PCBAssembleDetail : BaseRepository<PCBAssembleDetailInfo>, IPCBAssembleDetail 
    {
        private const string PARM_ASSEMBLEDETAILS_PRODUCTSN = "@PCBASN";

        private const string PARM_ASSEMBLEDETAIPS_PCBTYPEID = "@PCBTypeID";
        private const string PARM_ASSEMBLEDETAILS_IPADDR = "@IPAddr";

        public IList<PCBAssembleDetailInfo> GetPCBAssembleDetailsbySN(string pCBASN)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = pCBASN;
            return ExcuteSqlToGetEntities("PCBAssembleDetail_selectbySN", parm);
        }

        public IList<PCBAssembleDetailInfo> GetPCBAssembleDetailbyIPPID(string pCBTypeID, string ip)
        {
            SqlParameter[] parms = GetIPPIDParameters();
            parms[0].Value = pCBTypeID;
            parms[1].Value = ip;
            return ExcuteSqlToGetEntities("PCBAssembleDetail_selectbyLastIPandPID", parms);
        }

        public SqlParameter[] GetIPPIDParameters()
        {
            SqlParameter[] Parms = null;
            Parms = new SqlParameter[]
            {
                new SqlParameter(PARM_ASSEMBLEDETAIPS_PCBTYPEID, SqlDbType.NVarChar, 50),
                new SqlParameter(PARM_ASSEMBLEDETAILS_IPADDR, SqlDbType.NVarChar, 20),
            };
            return Parms;
        }


        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override PCBAssembleDetailInfo GetEntityRecord(SqlDataReader rdr)
        {
            PCBAssembleDetailInfo pro = new PCBAssembleDetailInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetValue(2).ToString());
            return pro;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_ASSEMBLEDETAILS_PRODUCTSN, SqlDbType.NVarChar, 50);
            return Parm;
        }
    }
}
